<%--
  Created by IntelliJ IDEA.
  User: ttxs
  Date: 2023/7/17
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <script>
    function doPage(pageNo) {
      document.forms[0].pageNo.value = pageNo;
      document.forms[0].submit();
    }
  </script>
  <body>
  <h1>用户列表</h1>
  <div>${msg}</div>
  <a href="${pageContext.request.contextPath}/users?opr=toAdd">添加</a>
  <form action="${pageContext.request.contextPath}/users?opr=list" method="post">
<%--    <input name="pageNo" type="hidden"/>--%>
    realName:<input name="realName" value="${realName}"/>
    roleId:<select name="roleId">

      <option value="">请选择</option>
      <option <c:if test="${roleId ==1}">selected</c:if> value="1">管理员</option>
      <option <c:if test="${roleId ==2}">selected</c:if> value="2">经理</option>
      <option <c:if test="${roleId ==3}">selected</c:if> value="3">用户</option>
  </select>
    <input type="submit" value="查询">
  <table>
    <tr>
      <td>ID</td>
      <td>account</td>
      <td>realName</td>
      <td>birthday</td>
      <td>操作</td>
    </tr>
    <c:forEach var="item" items="${page.list}" varStatus="i">

    <tr <c:if test="${i.count%2==0}">style="background-color: antiquewhite"</c:if>>
      <td>${item.id}</td>
      <td>${item.account}</td>
      <td>${item.realName}</td>
      <td><fmt:formatDate value="${item.birthday}" pattern="yyyy.MM.dd"/> </td>
      <td>
        <a href="${pageContext.request.contextPath}/users?opr=toUpdate&id=${item.id}">修改</a>
        <a href="${pageContext.request.contextPath}/users?opr=del&id=${item.id}">删除</a>
      </td>
    </tr>
    </c:forEach>
  </table>
  <div>
    当前${page.pageNo}/${page.totalPages}页，共${page.total}条，每页<input onchange="doPage(${page.pageNo})" size="2" name="pageSize" value="${page.pageSize}">条
  </div>
    <div>
      <a href="javascript:void(0)" onclick="doPage(1)">首页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.pageNo - 1})">上页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.pageNo + 1})">下页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.totalPages})">尾页</a>

      <select name="pageNo" onchange="doPage(this.value)">
        <c:forEach var="i"  begin="1" end="${page.totalPages}">
          <option <c:if test="${i ==page.pageNo}">selected</c:if> value="${i}">${i}</option>
        </c:forEach>
      </select>
      <c:forEach var="i" begin="1" end="${page.totalPages}">
        <a href="javascript:void(0)" <c:if test="${i ==page.pageNo}">style="color: red"</c:if>  onclick="doPage(${i})"> ${i}</a>
      </c:forEach>
    </div>

  </form>
  </body>
</html>
